package com.visiontech.volunteer_center.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdministratorInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String account = (String)session.getAttribute("account");
        Integer roleId = (Integer) session.getAttribute("roleId");
        if(account != null && roleId == 1){
            return true;
        }else {
            request.getRequestDispatcher("/user/login").forward(request, response);
            return false;
        }
    }
}
